<%-- 
    Document   : db4
    Created on : 2014/8/19, 下午 01:26:16
    Author     : Felix
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
        String id = request.getParameter("id");//接收list各個欄位的id
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/javadb","root","root");
        Statement st = con.createStatement();
        //String sql="insert into person(username,tel,birthday) values('Tom','02-222222','2050/01/01')";
        String sql="select id, username, tel, birthday from person where id="+id;//sql查詢資料庫資料語法
        
    %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <%
            ResultSet rs = st.executeQuery(sql);//要把要顯示的資料庫資料所設的語法放入此ResultSet介面
            if(rs.next())//如果有資料，逐一把游標往下移動抓出指定資料
            {
                
                String username = rs.getString("username");//設定變數並把設定的每項欄位資料轉成String指定給變數
                String tel = rs.getString("tel");
                String birthday = rs.getString("birthday");
                %>
                <form action="update2.jsp">
                username:<input type="text" name="username" value="<%=username%>"><br>
                tel:<input type="text" name="tel" value="<%=tel%>"><br>
                birthday:<input type="text" name="birthday" value="<%=birthday%>"><br>
                <input type="hidden" name="id" value="<%=id%>">
                <input type="submit" value="送出">
                </form>
                <%
                //out.println(id+","+username+","+tel+","+birthday+"<br>");//印出資料庫欄位資料
            }else//如果無資料
            {
                out.println("查無資料");
            }
                
            rs.close();//使用完須關閉
            st.close();
            con.close();
            
        %>
        
    </body>
</html>
